<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>模板过滤器</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
        .red {background-color: red;}
        .blue {background-color: blue;}
        .gray {background-color: gray;}
    </style>
</head>
<body>
<h1>模板标签</h1>

<ul>
    {% for book in books %}
        {% if book.id <= 2 %}
            <li class="red">{{ book.btitle }}--{{ book.bpub_date|date:'Y-m-d' }}</li>
        {% else %}
            {#  加了length后，会将原来的图书名编程图书名长度的数字  #}
            <li class="gray">{{ book.btitle|length }}--{{ book.bpub_date }}</li>
        {% endif %}
    {% endfor %}
</ul>
default过滤器：
{#  如果content没有值，则过滤器会显示默认的值  #}
{{ content|default:"hello" }}

</body>
</html>

booktest/temp_filter.html